<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%bank_guarantee_company_bind}}".
 *
 * @property integer $id
 * @property integer $bank_id
 * @property integer $guarantee_company_id
 * @property string $apigw_appid
 * @property string $apigw_format
 * @property string $apigw_signtype
 * @property string $apigw_version
 * @property resource $company_private_key
 * @property resource $bank_public_key
 * @property string $assurerno
 *
 * @property Bank $bank
 * @property GuaranteeCompany $guaranteeCompany
 */
class BankGuaranteeCompanyBind extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%bank_guarantee_company_bind}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['bank_id', 'guarantee_company_id', 'apigw_appid', 'apigw_signtype', 'apigw_version', 'company_private_key', 'bank_public_key', 'assurerno'], 'required'],
            [['bank_id', 'guarantee_company_id'], 'integer'],
            [['company_private_key', 'bank_public_key'], 'string'],
            [['apigw_appid'], 'string', 'max' => 50],
            [['apigw_format', 'apigw_signtype', 'assurerno'], 'string', 'max' => 20],
            [['apigw_version'], 'string', 'max' => 10],
            [['bank_id', 'guarantee_company_id'], 'unique', 'targetAttribute' => ['bank_id', 'guarantee_company_id'], 'message' => 'The combination of Bank ID and Guarantee Company ID has already been taken.'],
            [['bank_id'], 'exist', 'skipOnError' => true, 'targetClass' => Bank::className(), 'targetAttribute' => ['bank_id' => 'id']],
            [['guarantee_company_id'], 'exist', 'skipOnError' => true, 'targetClass' => GuaranteeCompany::className(), 'targetAttribute' => ['guarantee_company_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'bank_id' => 'Bank ID',
            'guarantee_company_id' => 'Guarantee Company ID',
            'apigw_appid' => 'Apigw Appid',
            'apigw_format' => 'Apigw Format',
            'apigw_signtype' => 'Apigw Signtype',
            'apigw_version' => 'Apigw Version',
            'company_private_key' => 'Company Private Key',
            'bank_public_key' => 'Bank Public Key',
            'assurerno' => 'Assurerno',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBank()
    {
        return $this->hasOne(Bank::className(), ['id' => 'bank_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGuaranteeCompany()
    {
        return $this->hasOne(GuaranteeCompany::className(), ['id' => 'guarantee_company_id']);
    }
}
